define(function (require,exports,module){
	/**--tmpl-require--**/

	var addmodule = require("admin/admin_nodeadd");

	var template = require('jtemplate');
	require('jdialog');
	common = require('common');

	exports.init = function(){
		/**--tmpl-todo--**/

		/**-- deleteopt --**/
		$(".js-delete").click(function(){
			var id = $(this).attr('data-id');
			layer.confirm('确定要删除吗',['确定','取消'],function(){
				layer.load();
				$.post(exports.deleteUrl,{id:id},function(data){
					layer.closeAll('loading');
					if(data.code == 0 || data.code=='success'){
						layer.msg('删除成功');
						document.location.reload();
					}else{
						layer.msg(data.message);
					}
				},'json');
			});
		});
		$("#add-node").click(function(){
			var tmpl = template('editpanel');
			var config = {
				title : '添加权限',
				content : tmpl,
				height : 400,
				button : {
					'保存' : function(){
					}
				}
			};
			exports.dlg = JDialog.win.work($.extend(__global.jdialog,config));
			$(".jdialog_win_buttonInner a.btn.btn-primary").AjaxProxy({
				url : exports.addUrl,
				dataType : "json",
				method : "post",
				formId : "content-add-form",
				formCheckHandler : function(form_id) {
					var r =  common.formCheckHandler(form_id, true);
					if(r){
						exports.dlg.lock();
					}
					return r;
				},
				callbackDelay : __global.jdialog.timer,
				timeInterval : __global.jdialog.timer,
				callBack : function (data) {   /* 执行ajax之后的回调函数 */
					common.ajaxCallback(data);
					exports.dlg.unlock();
					if(data.code == '000'){
						exports.dlg.close();
						
						location.reload();
					}
				}
			});
		});
		$(".js-edit").click(function(){
			$.get(exports.detailUrl ,{id:$(this).attr('data-id')},function(detail){
				console.log(detail);
				var tmpl = template('editpanel',detail);
				var config = {
					title : '编辑权限',
					content : tmpl,
					height : 400,
					button : {
						'保存' : function(){
						}
					}
				};
				exports.dlg = JDialog.win.work($.extend(__global.jdialog,config));
				$(".jdialog_win_buttonInner a.btn.btn-primary").AjaxProxy({
					url : exports.editUrl,
					dataType : "json",
					method : "post",
					formId : "content-add-form",
					formCheckHandler : function(form_id) {
						var r =  common.formCheckHandler(form_id, true);
						if(r){
							exports.dlg.lock();
						}
						return r;
					},
					callbackDelay : __global.jdialog.timer,
					timeInterval : __global.jdialog.timer,
					callBack : function (data) {   /* 执行ajax之后的回调函数 */
						common.ajaxCallback(data);
						exports.dlg.unlock();
						if(data.code == '000'){
							exports.dlg.close();
							location.reload();
						}
					}
				});

			},'json');

		});

		$('table#J_ListTable tr td:nth-child(2)').click(function(){
			var id = $(this).attr('data-id');
			var text = $(this).text();
			exports.tmptext = text;
			$(this).empty();
			var ipt = $('<input class="form-control" type="text" name="name" id="editname" placeholder="'+text+'" value="" />');
			ipt.blur(function(){
				var vipt = $(this).val();
				var td = $(this).parent();
				td.empty();
				if(vipt == '')
				{
					td.text(exports.tmptext);
				}
				else{
					console.log(exports.editUrl);
					$.post(exports.editUrl,{id:id,data:{name : vipt}},function(data){
						if(data.code == '000'){
							td.text(vipt);
						}else{
						
							td.text(exports.tmptext);
						}
					},'json');
				}
			});
			$(this).append(ipt);
			ipt.focus();
		});
		

		/**--tmpl-othertodo--**/
	};

	/**--tmpl-otherfunction--**/
});
